package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.service.ProductCategoryService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/product/category")
@CrossOrigin
@Api(value = "产品分类", description = "产品分类")
public class ProductCategoryController {

    private final ProductCategoryService productCategoryService;

    public ProductCategoryController(ProductCategoryService productCategoryService) {
        this.productCategoryService = productCategoryService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增产品分类接口",notes = "新增产品分类接口")
    public LogicResponse save(@RequestBody @Validated ProductCategoryCreateDTO productCategoryCreateDTO) {
        productCategoryService.saveProductCategory(productCategoryCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改产品分类接口",notes = "修改产品分类接口")
    public LogicResponse save(@RequestBody @Validated ProductCategoryUpdateDTO productCategoryUpdateDTO) {
        productCategoryService.updateProductCategory(productCategoryUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除产品分类接口",notes = "删除产品分类接口")
    public LogicResponse delete(@RequestBody @Validated ProductCategoryIdDTO productCategoryIdDTO) {
        productCategoryService.deleteProductCategory(productCategoryIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询产品分类列表接口",notes = "查询产品分类列表接口")
    public LogicResponse queryArticlePage(@RequestBody @Validated ProductCategoryQueryDTO productCategoryQueryDTO) {
        return LogicResponse.success(productCategoryService.getProductCategoryList(productCategoryQueryDTO));
    }

    @PostMapping("/sort")
    @ApiOperation(value = "产品分类顺序调整接口",notes = "产品分类顺序调整接口")
    public LogicResponse sort(@RequestBody @Validated ProductCategorySortDTO productCategorySortDTO) {
        productCategoryService.updateProductCategorySort(productCategorySortDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个产品分类的详情")
    public LogicResponse getProductDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(productCategoryService.getProductCategoryDetail(baseIdDTO));
    }
}
